#include <iostream>
#include "TcpServer.hpp"
#include "Calculator.hpp"

Calculator calculator;

void DeafaultOnMessage(std::weak_ptr<Connection> conn)
{
    auto connection = conn.lock();
    lg(Debug, "上层收到了数据: %s", connection->Inbuffer());
    // 对报文进行处理
    std::string resp = calculator.Handler(connection->Inbuffer());
    if(resp.empty()) return;
    lg(Debug, "%s", resp.c_str());
    connection->AppendOutbuffer(resp);
    connection->_tcpsvr_ptr.lock()->Sender(connection);
}

int main()
{
    std::shared_ptr<TcpServer> psvr(new TcpServer(8888, DeafaultOnMessage));
    psvr->Init();
    psvr->Loop();
    return 0;
}